<HTML>
<HEAD>
<TITLE>JavaScript Source Code 3000:  Clocks:  Silly Clock</TITLE>
<META HTTP-EQUIV="JavaScript Source Code 3000" CONTENT = "no-cache">
<META NAME="description" CONTENT="This analog clock will follow your cursor around the screen and continuously update.  Awesome!">
<META NAME="date" CONTENT="2000-12-11">
<META NAME="channel" CONTENT="Web Developer">
<META NAME="author" CONTENT="Kurt Grigg">
<META NAME="section" CONTENT="Clocks">
<SCRIPT LANGUAGE="JavaScript">
<!-- Original:  Kurt Grigg (kurt.grigg@virgin.net) -->
<!-- Web Site:  http://website.lineone.net/~kurt.grigg/javascript -->




<!-- Begin
colors = new Array('330099','00ff00','ff00ff');  //Clock face colors.
sCol = 'ff00ff';  //seconds colour.
mCol = '00ff00';  //minutes colour.
hCol = '330099';  //hours colour.
//Alter nothing below!
H = 'Hours..';
H = H.split('');
H = H.reverse();
M = 'Minutes..';
M = M.split('');
M = M.reverse();
S = 'Seconds..';
S = S.split('');
S = S.reverse();
dots = 12;
var Ypos = 0,Xpos = 0,Ybase = 0,Xbase = 0;
var ay = 0, ax = 0, Ay = 0, Ax = 0, by = 0, bx = 0, By = 0, Bx = 0, cy = 0, cx = 0, Cy = 0, Cx = 0, dy = 0, dx = 0, Dy = 0, Dx = 0;
count = 0;
count_a = 0;
move = 1;
ns = (document.layers)?1:0;
viz = (document.layers)?'hide':'hidden';
if (ns) {
for (i = 0; i < dots; i++)
document.write('<layer name=nface'+i+' top=0 left=0 bgcolor=#ffffff clip="0,0,3,3"></layer>');
for (i = 0; i < S.length; i++)
document.write('<layer name=nx'+i+' top=0 left=0 width=36 height=36><font face=Verdana size=2 color='+sCol+'><center>'+S[i]+'</center></font></layer>');
for (i = 0; i < M.length; i++)
document.write('<layer name=ny'+i+' top=0 left=0 width=36 height=36><font face=Verdana size=2 color='+mCol+'><center>'+M[i]+'</center></font></layer>');
for (i = 0; i < H.length; i++)
document.write('<layer name=nz'+i+' top=0 left=0 width=36 height=36><font face=Verdana size=2 color='+hCol+'><center>'+H[i]+'</center></font></layer>');
}
else{
document.write('<div id="W" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
for (i = 0; i < dots; i++) {
document.write('<div id="face" style="position:absolute;top:0px;left:0px;width:3px;height:3px;font-size:3px;background:#ffffff"></div>');
}
document.write('</div></div>');
document.write('<div id="X" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
for (i = 0; i < S.length; i++) {
document.write('<div id="x" style="position:absolute;width:36px;height:36px;font-family:Verdana;font-size:12px;color:'+sCol+';text-align:center;padding-top:10px">'+S[i]+'</div>');
}
document.write('</div></div>')
document.write('<div id="Y" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
for (i = 0; i < M.length; i++) {
document.write('<div id="y" style="position:absolute;width:36px;height:36px;font-family:Verdana;font-size:12px;color:'+mCol+';text-align:center;padding-top:10px">'+M[i]+'</div>');
}
document.write('</div></div>')
document.write('<div id="Z" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
for (i = 0; i < H.length; i++) {
document.write('<div id="z" style="position:absolute;width:36px;height:36px;font-family:Verdana;font-size:12px;color:'+hCol+';text-align:center;padding-top:10px">'+H[i]+'</div>');
}
document.write('</div></div>');
}
if (ns) {
window.captureEvents(Event.MOUSEMOVE);
function nsMouse(evnt) {
Ypos = evnt.pageY + 100;
Xpos = evnt.pageX + 100;
}
window.onMouseMove = nsMouse;
}
else{
function ieMouse() {
Ypos = event.y + 100;
Xpos = event.x + 100;
}
document.onmousemove = ieMouse;
}
function clock() {
time = new Date ();
secs = time.getSeconds();
sec = -1.57 + Math.PI * secs / 30;
mins = time.getMinutes();
min = -1.57 + Math.PI * mins / 30;
hr = time.getHours();
hrs = -1.575 + Math.PI * hr / 6 + Math.PI * parseInt(time.getMinutes()) / 360;
Ybase = 15;
Xbase = 15;
if (ns) {
document.layers["nx"+0].visibility = viz;
document.layers["ny"+0].visibility = viz;
document.layers["nz"+0].visibility = viz;
for (i = 0; i < S.length; i++) {
document.layers["nx"+i].top = ay - 12 + (i * Ybase) * Math.sin(sec);
document.layers["nx"+i].left = ax - 12 + (i * Xbase) * Math.cos(sec);
}
for (i = 0; i < M.length; i++) {
document.layers["ny"+i].top = by - 12 + (i * Ybase) * Math.sin(min);
document.layers["ny"+i].left = bx - 12 + (i * Xbase) * Math.cos(min);
}
for (i = 0; i < H.length; i++) {
document.layers["nz"+i].top = cy - 12 + (i * Ybase) * Math.sin(hrs);
document.layers["nz"+i].left = cx - 12 + (i * Xbase) * Math.cos(hrs);
}
for (i = 0; i < dots; ++i) {
document.layers["nface"+i].top = dy - 2 + (70 * Math.sin(-0.49+dots+i/1.9));
document.layers["nface"+i].left = dx + 4 + (70 * Math.cos(-0.49+dots+i/1.9));
   }
}
else {
var scrll = document.body.scrollTop;
W.style.pixelTop = scrll;
X.style.pixelTop = scrll;
Y.style.pixelTop = scrll;
Z.style.pixelTop = scrll;
x[0].style.visibility=viz;
y[0].style.visibility = viz;
z[0].style.visibility = viz;
for (i = 0; i < S.length; i++) {
x[i].style.pixelTop = ay - 12 + (i * Ybase) * Math.sin(sec);
x[i].style.pixelLeft = ax - 12 + (i * Xbase) * Math.cos(sec);
}
for (i = 0; i < M.length; i++) {
y[i].style.pixelTop = by - 12 + (i * Ybase) * Math.sin(min);
y[i].style.pixelLeft = bx - 12 + (i * Xbase) * Math.cos(min);
}
for (i = 0; i < H.length; i++) {
z[i].style.pixelTop = cy - 12 + (i * Ybase) * Math.sin(hrs);
z[i].style.pixelLeft = cx - 12 + (i * Xbase) * Math.cos(hrs);
}
for (i = 0; i < dots; ++i) {
face[i].style.pixelTop = dy + 6 + (70 * Math.sin(-0.49 + dots + i / 1.9));
face[i].style.pixelLeft = dx + 4 + (70 * Math.cos(-0.49 + dots + i / 1.9));
      }
   }
}
function MouseFollow() {
ay = Math.round(Ay += ((Ypos) - Ay) * 4 / 15);
ax = Math.round(Ax += ((Xpos) - Ax) * 4 / 15);
by = Math.round(By += (ay - By) * 4 / 15);
bx = Math.round(Bx += (ax - Bx) * 4 / 15);
cy = Math.round(Cy += (by - Cy) * 4 / 15);
cx = Math.round(Cx += (bx - Cx) * 4 / 15);
dy = Math.round(Dy += (cy - Dy) * 4 / 15);
dx = Math.round(Dx += (cx - Dx) * 4 / 15);
clock();
setTimeout('MouseFollow()',10);
}
function colorstep() {
count +=move;
if (count >= dots) {count=0;count_a += move}
if (count_a == colors.length) count_a = 0;
if (ns) document.layers["nface"+count].bgColor = colors[count_a];
else face[count].style.background = colors[count_a];
setTimeout('colorstep()',100)
}
function StartAll() {
MouseFollow();
colorstep();
}
if (document.layers || document.all) window.onload = StartAll;
//  End -->
</script>

</HEAD>

<BODY BGCOLOR=#ffffff vlink=#0000ff>

<BR>
<center>
<table width=600 cellpadding=0 cellspacing=10>
<tr>
<td width=468 align=center>

    
    
</td>
<td width=120 align=center>
    
</td>
</tr>
</table>
<BR>
<BR>
<basefont size=3>
<FONT SIZE="+2" FACE="Helvetica,Arial">
<A HREF="../index.htm" /" TARGET="_top"><FONT COLOR="#0000FF"><b>Home</b></font></A>
<img src="../img/arrow.gif" /img/arrow.gif" height=13 width=7 border=0 alt="}">
<A HREF="index.htm" /clocks/"><font color="#FF0000"><b>Clocks</b></font></A>
<img src="../img/arrow.gif" /img/arrow.gif" height=13 width=7 border=0 alt="}">
<FONT COLOR="#006666"><b>Silly Clock</b></font></font>
<BR>
<BR>
<table BORDER=0 WIDTH=486 CELLPADDING=3 CELLSPACING=0>
<tr><td><font FACE="helvetica,arial,geneva">
<br>
<br>
<!-- Description --><!--content_start-->
This analog clock will follow your cursor around the screen and continuously update.  Awesome!
<hr>
</td></tr>
</table>
<!-- Demonstration -->

<P>
<P>
<a name="source">
<table BORDER=0 WIDTH=486 CELLPADDING=3 CELLSPACING=0>
<tr><td BGCOLOR=yellow><font FACE="helvetica,arial,geneva"><b>JavaScript Source Code 3000:  Clocks:  Silly Clock</b>
<p>Simply click inside the window below, use your cursor to highlight the script, and copy (type Control-c or Apple-c) the script into a new file in your text editor (such as Note Pad or Simple Text) and save (Control-s or Command-s).  The script is yours!!!
<br><br></font></td></tr>
<tr><td BGCOLOR=yellow ALIGN=CENTER>
<form NAME="copy">

<DIV align="center">
<input type=button value="Highlight All" onClick="javascript:this.form.txt.focus();this.form.txt.select();">&nbsp;&nbsp;&nbsp;&nbsp;
<INPUT TYPE="text" NAME="total" VALUE="Script Size:  6.73 KB" size=24>
</DIV>

<textarea NAME="txt" ROWS=20 COLS=75 WRAP=VIRTUAL>

&lt;!-- ONE STEP TO INSTALL SILLY CLOCK:

  1.  Copy the coding into the HEAD of your HTML document  --&gt;

&lt;!-- STEP ONE: Paste this code into the HEAD of your HTML document  --&gt;

&lt;HEAD&gt;

&lt;SCRIPT LANGUAGE="JavaScript"&gt;
&lt;!-- Original:  Kurt Grigg (kurt.grigg@virgin.net) --&gt;
&lt;!-- Web Site:  http://website.lineone.net/~kurt.grigg/javascript --&gt;

&lt;! &gt;
&lt;! &gt;

&lt;!-- Begin
colors = new Array('330099','00ff00','ff00ff');  //Clock face colors.
sCol = 'ff00ff';  //seconds colour.
mCol = '00ff00';  //minutes colour.
hCol = '330099';  //hours colour.
//Alter nothing below!
H = 'Hours..';
H = H.split('');
H = H.reverse();
M = 'Minutes..';
M = M.split('');
M = M.reverse();
S = 'Seconds..';
S = S.split('');
S = S.reverse();
dots = 12;
var Ypos = 0,Xpos = 0,Ybase = 0,Xbase = 0;
var ay = 0, ax = 0, Ay = 0, Ax = 0, by = 0, bx = 0, By = 0, Bx = 0, cy = 0, cx = 0, Cy = 0, Cx = 0, dy = 0, dx = 0, Dy = 0, Dx = 0;
count = 0;
count_a = 0;
move = 1;
ns = (document.layers)?1:0;
viz = (document.layers)?'hide':'hidden';
if (ns) {
for (i = 0; i &lt; dots; i++)
document.write('&lt;layer name=nface'+i+' top=0 left=0 bgcolor=#ffffff clip="0,0,3,3"&gt;&lt;/layer&gt;');
for (i = 0; i &lt; S.length; i++)
document.write('&lt;layer name=nx'+i+' top=0 left=0 width=36 height=36&gt;&lt;font face=Verdana size=2 color='+sCol+'&gt;&lt;center&gt;'+S[i]+'&lt;/center&gt;&lt;/font&gt;&lt;/layer&gt;');
for (i = 0; i &lt; M.length; i++)
document.write('&lt;layer name=ny'+i+' top=0 left=0 width=36 height=36&gt;&lt;font face=Verdana size=2 color='+mCol+'&gt;&lt;center&gt;'+M[i]+'&lt;/center&gt;&lt;/font&gt;&lt;/layer&gt;');
for (i = 0; i &lt; H.length; i++)
document.write('&lt;layer name=nz'+i+' top=0 left=0 width=36 height=36&gt;&lt;font face=Verdana size=2 color='+hCol+'&gt;&lt;center&gt;'+H[i]+'&lt;/center&gt;&lt;/font&gt;&lt;/layer&gt;');
}
else{
document.write('&lt;div id="W" style="position:absolute;top:0px;left:0px"&gt;&lt;div style="position:relative"&gt;');
for (i = 0; i &lt; dots; i++) {
document.write('&lt;div id="face" style="position:absolute;top:0px;left:0px;width:3px;height:3px;font-size:3px;background:#ffffff"&gt;&lt;/div&gt;');
}
document.write('&lt;/div&gt;&lt;/div&gt;');
document.write('&lt;div id="X" style="position:absolute;top:0px;left:0px"&gt;&lt;div style="position:relative"&gt;');
for (i = 0; i &lt; S.length; i++) {
document.write('&lt;div id="x" style="position:absolute;width:36px;height:36px;font-family:Verdana;font-size:12px;color:'+sCol+';text-align:center;padding-top:10px"&gt;'+S[i]+'&lt;/div&gt;');
}
document.write('&lt;/div&gt;&lt;/div&gt;')
document.write('&lt;div id="Y" style="position:absolute;top:0px;left:0px"&gt;&lt;div style="position:relative"&gt;');
for (i = 0; i &lt; M.length; i++) {
document.write('&lt;div id="y" style="position:absolute;width:36px;height:36px;font-family:Verdana;font-size:12px;color:'+mCol+';text-align:center;padding-top:10px"&gt;'+M[i]+'&lt;/div&gt;');
}
document.write('&lt;/div&gt;&lt;/div&gt;')
document.write('&lt;div id="Z" style="position:absolute;top:0px;left:0px"&gt;&lt;div style="position:relative"&gt;');
for (i = 0; i &lt; H.length; i++) {
document.write('&lt;div id="z" style="position:absolute;width:36px;height:36px;font-family:Verdana;font-size:12px;color:'+hCol+';text-align:center;padding-top:10px"&gt;'+H[i]+'&lt;/div&gt;');
}
document.write('&lt;/div&gt;&lt;/div&gt;');
}
if (ns) {
window.captureEvents(Event.MOUSEMOVE);
function nsMouse(evnt) {
Ypos = evnt.pageY + 100;
Xpos = evnt.pageX + 100;
}
window.onMouseMove = nsMouse;
}
else{
function ieMouse() {
Ypos = event.y + 100;
Xpos = event.x + 100;
}
document.onmousemove = ieMouse;
}
function clock() {
time = new Date ();
secs = time.getSeconds();
sec = -1.57 + Math.PI * secs / 30;
mins = time.getMinutes();
min = -1.57 + Math.PI * mins / 30;
hr = time.getHours();
hrs = -1.575 + Math.PI * hr / 6 + Math.PI * parseInt(time.getMinutes()) / 360;
Ybase = 15;
Xbase = 15;
if (ns) {
document.layers["nx"+0].visibility = viz;
document.layers["ny"+0].visibility = viz;
document.layers["nz"+0].visibility = viz;
for (i = 0; i &lt; S.length; i++) {
document.layers["nx"+i].top = ay - 12 + (i * Ybase) * Math.sin(sec);
document.layers["nx"+i].left = ax - 12 + (i * Xbase) * Math.cos(sec);
}
for (i = 0; i &lt; M.length; i++) {
document.layers["ny"+i].top = by - 12 + (i * Ybase) * Math.sin(min);
document.layers["ny"+i].left = bx - 12 + (i * Xbase) * Math.cos(min);
}
for (i = 0; i &lt; H.length; i++) {
document.layers["nz"+i].top = cy - 12 + (i * Ybase) * Math.sin(hrs);
document.layers["nz"+i].left = cx - 12 + (i * Xbase) * Math.cos(hrs);
}
for (i = 0; i &lt; dots; ++i) {
document.layers["nface"+i].top = dy - 2 + (70 * Math.sin(-0.49+dots+i/1.9));
document.layers["nface"+i].left = dx + 4 + (70 * Math.cos(-0.49+dots+i/1.9));
   }
}
else {
var scrll = document.body.scrollTop;
W.style.pixelTop = scrll;
X.style.pixelTop = scrll;
Y.style.pixelTop = scrll;
Z.style.pixelTop = scrll;
x[0].style.visibility=viz;
y[0].style.visibility = viz;
z[0].style.visibility = viz;
for (i = 0; i &lt; S.length; i++) {
x[i].style.pixelTop = ay - 12 + (i * Ybase) * Math.sin(sec);
x[i].style.pixelLeft = ax - 12 + (i * Xbase) * Math.cos(sec);
}
for (i = 0; i &lt; M.length; i++) {
y[i].style.pixelTop = by - 12 + (i * Ybase) * Math.sin(min);
y[i].style.pixelLeft = bx - 12 + (i * Xbase) * Math.cos(min);
}
for (i = 0; i &lt; H.length; i++) {
z[i].style.pixelTop = cy - 12 + (i * Ybase) * Math.sin(hrs);
z[i].style.pixelLeft = cx - 12 + (i * Xbase) * Math.cos(hrs);
}
for (i = 0; i &lt; dots; ++i) {
face[i].style.pixelTop = dy + 6 + (70 * Math.sin(-0.49 + dots + i / 1.9));
face[i].style.pixelLeft = dx + 4 + (70 * Math.cos(-0.49 + dots + i / 1.9));
      }
   }
}
function MouseFollow() {
ay = Math.round(Ay += ((Ypos) - Ay) * 4 / 15);
ax = Math.round(Ax += ((Xpos) - Ax) * 4 / 15);
by = Math.round(By += (ay - By) * 4 / 15);
bx = Math.round(Bx += (ax - Bx) * 4 / 15);
cy = Math.round(Cy += (by - Cy) * 4 / 15);
cx = Math.round(Cx += (bx - Cx) * 4 / 15);
dy = Math.round(Dy += (cy - Dy) * 4 / 15);
dx = Math.round(Dx += (cx - Dx) * 4 / 15);
clock();
setTimeout('MouseFollow()',10);
}
function colorstep() {
count +=move;
if (count &gt;= dots) {count=0;count_a += move}
if (count_a == colors.length) count_a = 0;
if (ns) document.layers["nface"+count].bgColor = colors[count_a];
else face[count].style.background = colors[count_a];
setTimeout('colorstep()',100)
}
function StartAll() {
MouseFollow();
colorstep();
}
if (document.layers || document.all) window.onload = StartAll;
//  End --&gt;
&lt;/script&gt;


 

&lt;!-- Script Size:  6.73 KB --&gt;</textarea><br><font FACE="helvetica,arial,geneva"></font></td></tr>

</table>
</form>
</FONT>
</CENTER>


</center>
</body></html>
